package com.pk.platform.business.data.web;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.pk.platform.business.core.web.GenericAction;
import com.pk.platform.business.data.service.IMasterDataService;
import com.pk.platform.domain.data.Employee;
import com.pk.platform.util.StringConverter;

@ParentPackage("default")
@Namespace("/inner/masterData")
public class MasterDataAction extends GenericAction {

	private IMasterDataService masterDataService;
	
	private Employee employee = new Employee();
	
	@Action(value="employeeManage", 
			results={@Result(name="success", 
					location="/jsp/login/business/masterData/employee/employeeManage.jsp")})
	public String employeeManage()
	{
		super.initGrid();
		return SUCCESS;
	}
	
	@Action(value="toSaveEmployee", 
			results={@Result(name="success", 
					location="/jsp/login/business/masterData/employee/saveEmployee.jsp")})
	public String toSaveEmployee()
	{
		if(StringConverter.isNotNull(employee.getId()))
		{
			employee = masterDataService.queryEmployeeById(employee.getId());
		}
		return SUCCESS;
	}
	
	@Action(value="saveEmployee", 
			results={@Result(name="success", 
					type="json",
					params={"root", "message"})})
	public String saveEmployee()
	{
		message = masterDataService.saveEmployee(employee);
		return SUCCESS;
	}
	
	@Action(value="delEmployee", 
			results={@Result(name="success", 
					type="json")})
	public String delEmployee()
	{
		masterDataService.delEmployee(employee.getId());
		return SUCCESS;
	}
	
	@Action(value="toSelectEmployee", 
			results={@Result(name="success", 
					location="/jsp/login/business/masterData/employee/selectEmployee.jsp")})
	public String toSelectEmployee()
	{
		super.initGrid();
		return SUCCESS;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public IMasterDataService getMasterDataService() {
		return masterDataService;
	}

	public void setMasterDataService(IMasterDataService masterDataService) {
		this.masterDataService = masterDataService;
	}
	
}
